/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.smartercontext.contextmger.contextsphere;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author JuanPablo
 */
@Entity
@Table(name = "ctxtsphere", schema="contextsphere")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ctxtsphere.findAll", query = "SELECT c FROM Ctxtsphere c"),
    @NamedQuery(name = "Ctxtsphere.findByUsername", query = "SELECT c FROM Ctxtsphere c WHERE c.username = :username"),
    @NamedQuery(name = "Ctxtsphere.findByUpassword", query = "SELECT c FROM Ctxtsphere c WHERE c.upassword = :upassword")})
public class Ctxtsphere implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 16)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 16)
    @Column(name = "upassword")
    private String upassword;
    @Lob
    @Column(name = "rdfgraph")
    private byte[] rdfgraph;
    @JoinTable(name = "user_permissions", schema="contextsphere", joinColumns = {
    		@JoinColumn(name = "username", referencedColumnName = "username")}, inverseJoinColumns = {
    		@JoinColumn(name = "idPermission", referencedColumnName = "idPermission")})
    @ManyToMany
    private List<Permissions> permissionsList;

    public Ctxtsphere() {
    }

    public Ctxtsphere(String username) {
        this.username = username;
    }

    public Ctxtsphere(String username, String upassword) {
        this.username = username;
        this.upassword = upassword;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUpassword() {
        return upassword;
    }

    public void setUpassword(String upassword) {
        this.upassword = upassword;
    }

    public byte[] getRdfgraph() {
        return rdfgraph;
    }

    public void setRdfgraph(byte[] rdfgraph) {
        this.rdfgraph = rdfgraph;
    }

    @XmlTransient
    public List<Permissions> getPermissionsList() {
        return permissionsList;
    }

    public void setPermissionsList(List<Permissions> permissionsList) {
        this.permissionsList = permissionsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (username != null ? username.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ctxtsphere)) {
            return false;
        }
        Ctxtsphere other = (Ctxtsphere) object;
        if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.smartercontext.contextmger.contextsphere.Ctxtsphere[ username=" + username + " ]";
    }
    
}
